package com.yeyks.rabbitmq.rabbitlistener;

import com.yeyks.base.Arguments;
import com.yeyks.rabbitmq.queue.DelayRabbitMqQueue;
import com.yeyks.service.OrderService;
import com.yeyks.util.DateUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author fuchangshuai
 * @date 2019/4/17 0017
 */
@Component
@Slf4j
public class DelayQueueListener {

    @Autowired
    private OrderService orderService;

    //监听的队列名
    @RabbitListener(queues = DelayRabbitMqQueue.ORDER_QUEUE)
    public void pushMessage(String message) {
        log.info("接受到消息的时间：" + DateUtils.format(new Date()));
        if (!Arguments.notEmpty(message)) {
            return;
        }
        Integer res = orderService.updateCancleOrder(message);
        if (res == null) {
            log.info("该订单不存在orderNo = {}", message);
            return;
        }
        if (res == 0) {
            log.error("更新订单状态失败orderNo = {}", message);
        }

    }
}
